package client.test;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import socket.utils;
import Globle.Global;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ShowDriverInfo extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.showdriver);
	}

	
	public void request_driverinfoOnclicked(View v) throws UnsupportedEncodingException, IOException{
		byte[] sendmsg = new byte[1024];
		sendmsg[0] = Global.REQUESTDRIVERINFO;
		byte[] str = utils.client.sendMsg(new String(sendmsg));
		
		
		
		
		if(Global.RECVDRIVERINFO == Global.getMsgId(str))
		//if(str[0] == 0x00 && str[1]==0x01)
		{
			System.arraycopy(str, 4, sendmsg, 0, str.length-4);
			String msg = new String(sendmsg,"UTF-8");
			
			
		/*	根据 Java Language Specification 的要求，Java 源代码的字符串中的反斜线被解释为 Unicode 转义或其他字符转义。
			因此必须在字符串字面值中使用两个反斜线，
			表示正则表达式受到保护，不被 Java 字节码编译器解释。例如，当解释为正则表达式时，
			字符串字面值 "\b" 与单个退格字符匹配，而 "\\b" 与单词边界匹配。字符串字面值 "\(hello\)" 
			是非法的，将导致编译时错误；要与字符串 (hello) 匹配，必须使用字符串字面值 "\\(hello\\)"。
			为什么不能用 msg.split("|")*/
		    String [] driver = msg.split("\\|");
			
		   
			if (driver != null)
			{
				int count = 0;
				count = Integer.parseInt(driver[0]);	
			    StringBuilder s = new StringBuilder();
			    
			    s.append("dirver info:\n");
			    for (int i = 1; i <= count; i++)
			    {
			    	String []driverinfo =  driver[i].split("\\@");
			    	if(driverinfo != null)
			    	{
			    		s.append(driverinfo[0]);
			    		s.append("\nFrreSize: ");
			    		s.append(driverinfo[1]);
			    		s.append("GB");
			    		s.append("\nTotalSize: ");
			    		s.append(driverinfo[2]);
			    		s.append("GB");
			    	}
			    	s.append("\n");
			    }
				
			    TextView t = (TextView)findViewById(R.id.driver_text);
			    t.setText(s);
			}
		}
	}
}
